package com.st.globleadvice;

import com.st.base.BaseResult;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/*
该类为项目的全局异常处理类，会将程序中产生的异常，定项的做出处理
 */
@RestControllerAdvice
public class GlobleAdviceHandler {


    @ExceptionHandler(value = BindException.class)
    public BaseResult validationHandler(BindException e){
        String defaultMessage = e.getBindingResult().getFieldError().getDefaultMessage();
        return BaseResult.error(defaultMessage);
    }
}
